package com.cjx.springcloud.controller;

import com.cjx.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author cjx
 * @date 2021/6/10 0010 - 21:19
 */
@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class OrderHystrixController {
        @Resource
        private PaymentHystrixService paymentHystrixService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentinfo_ok(@PathVariable("id") Integer id){
        String result=paymentHystrixService.paymentinfo_ok(id);
        return result;
    }
//    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",commandProperties = {
//            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="5000")//设置 最大时间
//    })
    @HystrixCommand//服务降级
    @GetMapping("/consumer/payment/timeout/ok/{id}")
    public String paymentinfo_timeout(@PathVariable("id") Integer id){
        String result=paymentHystrixService.paymentinfo_timeout(id);
        return result;
    }

    public String paymentInfo_TimeOutHandler(Integer id){
        return  "线程池："+Thread.currentThread().getName()+"出错找我11111";
    }

    public String payment_Global_FallbackMethod(){
        return  "quanjuyichang";
    }
}
